# -*- coding: utf-8 -*-
"""
@Time: 2021/12/22 16:57
@Author: jins
@File: table_demandts.py
@Introduction: demandts表造数据
"""
from common.mysqlDataOperate import OperateMysql
import random
from datetime import datetime, timedelta

EfficacyOptions_list = [1, 2, 4, 8]


def insert(start):
    op = OperateMysql()
    for j in range(start + 1, start + 3):
        for k in EfficacyOptions_list:
            Pike = 2000.0
            Peak = 1500.0
            Flat = 1000.0
            Vale = 500.0
            data_time = datetime(2020, 11, 1, 0, 0, 0)
            fmt = '%Y%m%d'
            fmt_time = '%H%M%S'
            for i in range(2880):
                Total = Pike + Peak + Flat + Vale
                TimeNum = int(data_time.strftime(fmt_time))
                DateNum = int(data_time.strftime(fmt))
                device_id = 10000000 + j
                increase_num = random.uniform(5.0, 10.0)
                UpdateTime = data_time.timestamp() * 1000
                sql = f"""INSERT INTO xlcloud.demandts20b
                VALUES
                    (   
                        {device_id},
                        {DateNum},
                        {TimeNum},
                        {k},
                        {Total},
                        {Pike},
                        {Peak},
                        {Flat},
                        {Vale},
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        {UpdateTime}
                     )
                        """
                op.batch_excute(sql)
                Pike += increase_num
                Peak += increase_num
                Flat += increase_num
                Vale += increase_num
                data_time += timedelta(minutes=15)
            op.commit()
    op.close()


if __name__ == '__main__':
    insert(0)
